package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.R.bool;
import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWBitmap;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.resource.IORWFile;
import com.handinfo.android.game.Battle;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.game.item.ItemEquipment;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIShuraBattlefield implements IUIWindows {

	public DWFrame m_battle_jiesuan_frame = null;
	public Bitmap m_cr_jiesuan_tit = null;
	public Bitmap m_cr_tc_tit = null;
	public Bitmap m_cr_tuichu = null;
	public DWBackground m_djs_bg = null;
	public DWTextbox m_djs_tb = null;
	public Bitmap m_cr_djs = null;
	public Bitmap m_cr_xbj = null;
	public DWImageBox m_jiesuan_tuichu = null;
	public DWBackground m_jiesuan_zxbj = null;
	public DWBackground m_jiesuan_yxbj = null;
	public DWLabel m_lb_1 = new DWLabel("排名");
	public DWLabel m_lb_2 = new DWLabel("杀人数");
	public DWLabel m_list_tit_name[] = null;
	public String m_tit_name[] = { "排名", "名称", "分数" };
	public Bitmap m_cr_vip[] = new Bitmap[6];
	public Bitmap m_cr_camp[] = new Bitmap[2];
	public Bitmap m_cr_right_bg = null;
	public DWLabel m_list_lb[][] = null;
	public DWListbox m_listbox = null;
	public DWImageBox m_vip[] = null;
	public DWImageBox m_camp[] = null;
	public Bitmap m_cr_list_tiao = null;
	public Bitmap m_cr_right_xxbj = null;
	public Bitmap m_cr_sigle_zhanji = null;
	public DWBackground m_sigle_zhanji_bg = null;
	public DWTextbox m_sigle_zhanji_tb = null;
	public Bitmap m_cr_but = null;
	public Bitmap m_cr_but_anxiz = null;
	public DWListbox m_sigle_you_listbox = null;
	public Bitmap m_cr_grid = null;

	public void BattleJieSuan() {
		if (DWControlsManager.getInstance().contains(m_battle_jiesuan_frame)) {
			if (m_battle_jiesuan_frame != null) {
				DWControlsManager.getInstance().removeControl(m_battle_jiesuan_frame);
			}
		}
		m_battle_jiesuan_frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		DWControlsManager.getInstance().addControl(m_battle_jiesuan_frame);

		DWTitle m_battle_jiesuan_tit = new DWTitle("", m_battle_jiesuan_frame);
		m_battle_jiesuan_frame.addControl(m_battle_jiesuan_tit);
		DWImageBox m_battle_jiesuan_tit_ima = new DWImageBox(m_cr_jiesuan_tit);
		m_battle_jiesuan_tit_ima.setNearAnchor(m_battle_jiesuan_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_battle_jiesuan_frame.addControl(m_battle_jiesuan_tit_ima);

		m_jiesuan_tuichu = new DWImageBox(m_cr_tuichu);
		m_jiesuan_tuichu.setNearAnchor(m_battle_jiesuan_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_jiesuan_tuichu.setTouchZoomIn(20, 20);
		m_battle_jiesuan_frame.addControl(m_jiesuan_tuichu);
		m_jiesuan_tuichu.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWControlsManager.getInstance().removeControl(m_battle_jiesuan_frame);
				m_djs_time = 0;
				m_current = 0;
				DWGameManager.getInstance().getSendMessage().sendShuraBattleLeave();
			}
		});

		m_cr_djs = UIWindows.createImage("/img/newui/jindubiao_2.gnp");
		m_djs_bg = new DWBackground(m_cr_djs, 4 * DWFont.getDefaultFont().getFontSize(), m_battle_jiesuan_tit.getShowHeight());
		m_djs_tb = new DWTextbox("10秒");
		m_djs_bg.setNearAnchor(
				m_battle_jiesuan_tit_ima,
				Tools.RIGHT_VCENTER,
				Tools.LEFT_VCENTER,
				-(m_battle_jiesuan_tit.getShowWidth() / 2 - m_battle_jiesuan_tit_ima.getShowWidth() / 2 - m_cr_djs.getWidth()) / 2,
				0);
		m_djs_tb.setNearAnchor(m_djs_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_battle_jiesuan_frame.addControl(m_djs_bg);
		m_battle_jiesuan_frame.addControl(m_djs_tb);

		/**
		 * 结算界面的左侧相关的布局
		 */
		m_jiesuan_zxbj = new DWBackground(3 * (m_battle_jiesuan_frame.getShowWidth() - 30) / 5, m_battle_jiesuan_frame.getShowHeight() - (m_battle_jiesuan_tit.getShowHeight() - 20) - 30);
		m_jiesuan_zxbj.setNearAnchor(m_battle_jiesuan_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, (m_battle_jiesuan_tit.getShowHeight() - 20) + 15);
		m_battle_jiesuan_frame.addControl(m_jiesuan_zxbj);

		m_list_tit_name = new DWLabel[m_tit_name.length];
		for (int i = 0; i < m_tit_name.length; i++) {
			m_list_tit_name[i] = new DWLabel(m_tit_name[i]);
			m_list_tit_name[i].setBackgroundColor(Tools.ALPHA);
			m_list_tit_name[i].setTextColor(Tools.RED);
			// 上下左右都是5
			if (i == 0) {
				m_list_tit_name[i].setShowWideHigh(
						(m_jiesuan_zxbj.getShowWidth() - 10 - m_cr_vip[0].getWidth() - m_cr_camp[0].getWidth() - 7 * DWFont.getDefaultFont().getFontSize()) / 3,
						m_lb_1.getShowHeight());
				m_list_tit_name[i].setNearAnchor(m_jiesuan_zxbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 10);
			} else if (i == 1) {
				m_list_tit_name[i].setShowWideHigh(7 * DWFont.getDefaultFont().getFontSize(), m_lb_1.getShowHeight());
				m_list_tit_name[i].setNearAnchor(m_list_tit_name[i - 1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, m_cr_vip[0].getWidth() + m_cr_camp[0].getWidth(), 0);
			} else {
				m_list_tit_name[i].setShowWideHigh(
						2 * (m_jiesuan_zxbj.getShowWidth() - m_cr_vip[0].getWidth() - m_cr_camp[0].getWidth() - 7 * DWFont.getDefaultFont().getFontSize()) / 3,
						m_lb_1.getShowHeight());
				m_list_tit_name[i].setNearAnchor(m_list_tit_name[i - 1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
			}
			m_battle_jiesuan_frame.addControl(m_list_tit_name[i]);
		}

		m_listbox = new DWListbox(m_jiesuan_zxbj.getShowWidth() - 10, m_jiesuan_zxbj.getShowHeight() - 20 - m_lb_1.getShowHeight() - 5);
		m_listbox.setShowBackgroundRect(false);
		m_listbox.setNearAnchor(m_list_tit_name[0], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
		m_battle_jiesuan_frame.addControl(m_listbox);

		int m_index = m_listbox.getShowHeight() / m_lb_1.getShowHeight();
		if (m_index > m_battle_list.m_role_size) {
			m_index = m_battle_list.m_role_size;
		}
		m_list_lb = new DWLabel[m_index][m_list_tit_name.length];
		m_vip = new DWImageBox[m_index];
		m_camp = new DWImageBox[m_index];
		for (int i = 0; i < m_index; i++) {
			DWListSubItem m_lsi = new DWListSubItem();
			if (i % 2 == 0) {
				DWBackground m_list_tiao = new DWBackground(m_cr_list_tiao, m_listbox.getShowWidth(), m_lb_1.getShowHeight());
				m_list_tiao.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				m_lsi.addControls(m_list_tiao);
			}
			for (int j = 0; j < m_list_tit_name.length; j++) {
				m_list_lb[i][j] = new DWLabel("");
				m_list_lb[i][j].setBackgroundColor(Tools.ALPHA);
				if (j == 0) {
					m_list_lb[i][j].setName(Integer.toString(i + 1));
					m_list_lb[i][j].setShowWideHigh(
							(m_listbox.getShowWidth() - m_cr_vip[0].getWidth() - m_cr_camp[0].getWidth() - 7 * DWFont.getDefaultFont().getFontSize()) / 3,
							m_lb_1.getShowHeight());
					m_list_lb[i][j].setTextColor(Tools.ORANGE);
					m_list_lb[i][j].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				} else if (j == 1) {
					m_list_lb[i][j].setName(m_battle_list.m_role_name[i]);
					m_list_lb[i][j].setShowWideHigh(7 * DWFont.getDefaultFont().getFontSize(), m_lb_1.getShowHeight());
					m_list_lb[i][j].setNearAnchor(m_list_lb[i][j - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, m_cr_camp[0].getWidth() + m_cr_camp[0].getWidth(), 0);
				} else if (j == 2) {
					m_list_lb[i][j].setName(Tools.getMoney(m_battle_list.m_role_score[i]));
					m_list_lb[i][j].setShowWideHigh(
							2 * (m_listbox.getShowWidth() - m_cr_vip[0].getWidth() - m_cr_camp[0].getWidth() - 7 * DWFont.getDefaultFont().getFontSize()) / 3,
							m_lb_1.getShowHeight());
					m_list_lb[i][j].setTextColor(Tools.GREEN);
					m_list_lb[i][j].setNearAnchor(m_list_lb[i][j - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 0, 0);
				}
				m_lsi.addControls(m_list_lb[i][j]);
			}
			m_camp[i] = new DWImageBox(m_cr_camp[0]);
			m_camp[i].setNearAnchor(m_list_lb[i][1], Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			m_lsi.addControls(m_camp[i]);

			m_vip[i] = new DWImageBox(m_cr_vip[0]);
			m_vip[i].setShow(false);
			m_vip[i].setNearAnchor(m_camp[i], Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			m_lsi.addControls(m_vip[i]);
			if (m_battle_list.m_vip[i] > 0) {
				m_vip[i].setImage(m_cr_vip[m_battle_list.m_vip[i] - 1]);
				m_vip[i].setShow(true);
			}
			m_listbox.addSubItem(m_lsi);
		}

		/**
		 * 右侧的布局
		 */
		m_jiesuan_yxbj = new DWBackground(2 * (m_battle_jiesuan_frame.getShowWidth() - 30) / 5, m_battle_jiesuan_frame.getShowHeight() - (m_battle_jiesuan_tit.getShowHeight() - 20) - 30);
		m_jiesuan_yxbj.setNearAnchor(m_jiesuan_zxbj, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);
		m_battle_jiesuan_frame.addControl(m_jiesuan_yxbj);

		/**
		 * 蓝色的背景圈
		 */
		// /个人战绩图片
		DWImageBox m_sigle_zhanyi = new DWImageBox(m_cr_sigle_zhanji);
		m_sigle_zhanyi.setNearAnchor(m_jiesuan_yxbj, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 20);

		DWBackground m_ysbg = new DWBackground(m_cr_right_xxbj, m_jiesuan_yxbj.getShowWidth() - 20, 2 * (m_jiesuan_yxbj.getShowHeight() - 70) / 3);
		m_ysbg.setNearAnchor(m_sigle_zhanyi, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, -10);
		m_battle_jiesuan_frame.addControl(m_ysbg);
		m_battle_jiesuan_frame.addControl(m_sigle_zhanyi);

		DWBackground m_yxbg = new DWBackground(m_cr_right_xxbj, m_jiesuan_yxbj.getShowWidth() - 20, (m_jiesuan_yxbj.getShowHeight() - 60) / 3);
		m_yxbg.setNearAnchor(m_ysbg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 50);
		m_battle_jiesuan_frame.addControl(m_yxbg);

		m_sigle_you_listbox = new DWListbox(m_jiesuan_yxbj.getShowWidth() - 40, m_jiesuan_yxbj.getShowHeight() - m_cr_sigle_zhanji.getHeight() - 20 - 10 - 10);
		m_sigle_you_listbox.setNearAnchor(m_jiesuan_yxbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 20, 20 + m_sigle_zhanyi.getShowHeight() + 10);
		m_battle_jiesuan_frame.addControl(m_sigle_you_listbox);

		for (int i = 0; i < m_battle_list.m_item_size + 2; i++) {
			DWListSubItem m_lis = new DWListSubItem();
			if (i == 0) {
				m_sigle_zhanji_tb = new DWTextbox("<mark c=FFBB11>" + "个人排名：" + Tools.getMoney(m_battle_list.m_sigle_rank) + "</mark>" + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + "杀戮分数："
						+ Tools.getMoney(m_battle_list.m_sigle_score) + "</mark>" + DWControlTools.CHANGE_ROW + "<mark c=55FF00>" + "击杀人数：" + Tools.getMoney(m_battle_list.m_skill_num) + "</mark>"
						+ DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + "助攻人数：" + Tools.getMoney(m_battle_list.m_sigle_zhugong_count) + "</mark>" + DWControlTools.CHANGE_ROW + "<mark c=FFBB11>"
						+ "奖励战功：" + Tools.getMoney(m_battle_list.m_sigle_zhangong) + "</mark>" + DWControlTools.CHANGE_ROW, m_sigle_you_listbox.getShowWidth() - 20);
				m_sigle_zhanji_tb.setNearAnchor(m_lis, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
				m_lis.addControls(m_sigle_zhanji_tb);
			} else if (i == 1) {
				DWBackground m_zhongjian_tiao = new DWBackground(m_cr_right_bg, m_sigle_you_listbox.getShowWidth() - 10, m_cr_right_bg.getHeight());
				m_zhongjian_tiao.setNearAnchor(m_lis, Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 0);
				m_lis.addControls(m_zhongjian_tiao);
			} else {
				DWGrid m_grid = new DWGrid(m_cr_grid);
				m_grid.m_data = m_battle_list.m_item_list[i - 2];
				m_grid.setNearAnchor(m_lis, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
				final int m_grid_index = i - 2;
				m_grid.addListener(new DWListener() {

					public void OnDoubleClick() {
					}

					public void OnClick() {
						Item(m_battle_list.m_item_list[m_grid_index].m_key);
					}
				});
				DWTextbox m_text = new DWTextbox("<mark c=" + getNameColor(m_battle_list.m_item_list[i - 2].m_quality) + ">" + m_battle_list.m_item_list[i - 2].m_name + "</mark>" + "×"
						+ m_battle_list.m_item_list[i - 2].m_num, m_sigle_you_listbox.getShowWidth() - m_cr_grid.getWidth() - 5);
				m_text.setNearAnchor(m_grid, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);

				m_lis.addControls(m_grid);
				m_lis.addControls(m_text);
			}
			m_sigle_you_listbox.addSubItem(m_lis);
		}
	}

	public void Item(String key) {
		DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(0, key);
	}

	/**
	 * 获取item名字的颜色
	 * 
	 * @param item
	 * @return
	 */
	public static String getNameColor(int num) {
		String color = "";
		if (num >= 0) {
			switch (num) {
				case ItemConstants.稀有度_灰:
					color = "999999";
					break;
				case ItemConstants.稀有度_白:
					color = "ffffff";
					break;
				case ItemConstants.稀有度_蓝:
					color = "00BBFF";
					break;
				case ItemConstants.稀有度_绿:
					color = "55FF00";
					break;
				case ItemConstants.稀有度_紫:
					color = "9900FF";
					break;
				case ItemConstants.稀有度_橙:
					color = "FFBB11";
					break;
				case ItemConstants.稀有度_红:
					color = "FF3300";
					break;
			}
		}
		return color;
	}

	public void init() {

		m_cr_jiesuan_tit = UIWindows.createImage("/img/newui/xiuluoshachang_1.gnp");// 结算的标题
		m_cr_tc_tit = UIWindows.createImage("/img/newui/tuichuzhanchang_1.gnp");// 退出杀场的标题
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 退出
		m_cr_djs = UIWindows.createImage("/img/newui/jindubiao_2.gnp");
		m_cr_xbj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");
		m_cr_right_bg = UIWindows.createImage("/img/newui/datige_1.gnp");
		m_cr_list_tiao = UIWindows.createImage("/img/newui/paihangtiaobj_1.gnp");
		m_cr_right_xxbj = UIWindows.createImage("/img/newui/xiuluoshachangbj_1.gnp");
		m_cr_sigle_zhanji = UIWindows.createImage("/img/newui/gerenzhanji_1.gnp");
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp");
		m_cr_but_anxiz = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		m_cr_grid = UIWindows.createImage("/img/newui/wupinlan.gnp");

		m_cr_bitmap[0] = UIWindows.createImage("/img/newui/daojishi_1.gnp");
		m_cr_bitmap[1] = UIWindows.createImage("/img/newui/daojishi_2.gnp");
		m_cr_bitmap[2] = UIWindows.createImage("/img/newui/daojishi_3.gnp");
		m_cr_bitmap[3] = UIWindows.createImage("/img/newui/daojishi_4.gnp");
		m_cr_bitmap[4] = UIWindows.createImage("/img/newui/daojishi_5.gnp");
		m_cr_vip[0] = UIWindows.createImage("/img/newui/vip_1.gnp");
		m_cr_vip[1] = UIWindows.createImage("/img/newui/vip_2.gnp");
		m_cr_vip[2] = UIWindows.createImage("/img/newui/vip_3.gnp");
		m_cr_vip[3] = UIWindows.createImage("/img/newui/vip_4.gnp");
		m_cr_vip[4] = UIWindows.createImage("/img/newui/vip_5.gnp");
		m_cr_vip[5] = UIWindows.createImage("/img/newui/vip_6.gnp");
		m_cr_camp[0] = UIWindows.createImage("/img/newui/tianji_1.gnp");
		m_cr_camp[1] = UIWindows.createImage("/img/newui/lingyin_1.gnp");
	}

	public void open(byte index) {
	}

	public void close(byte index) {
	}

	public void dispose() {
	}

	/**
	 * 接收网络数据
	 */
	/**
	 * 战场开启提示框接收指令
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvBattlefieldOpenTishi(DataInputStream dis) throws IOException {
		byte m_state = dis.readByte();
		Tools.debugPrintln("战场开启提示框的接收状态：" + m_state);
		if (m_state == 0) {
			return;
		} else if (m_state == 1) {
			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "修罗战场已经开启，是否现在进入？开启时间内大家可以随时通过助手界面进入参加。", "确定", "返回");
			DWControlsManager.getInstance().addControl(m_mb);
			m_mb.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
						// /发送进入修罗战场的指令
					} else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
					}
					DWControlsManager.getInstance().removeControl(m_mb);
				}
			});
		}
	}

	/**
	 * 在助手界面进入的时候从NPC处进，点击的时候出现的提示框的接收指令,获取进入战场的战场id
	 */
	public DWFrame m_npc_frame = null;
	public long m_battle_id = 0;

	public void recvNPC(DataInputStream dis) throws IOException {
		byte m_state = dis.readByte();
		Tools.debugPrintln("状态：" + m_state);
		if (m_state == 0) {
//			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抱歉，操作失败。");
			Tools.debugPrintln("抱歉，操作失败。");
		} else if (m_state == 1) {
			m_battle_id = dis.readLong();
			Tools.debugPrintln("杀场ID：" + m_battle_id);
			if (DWControlsManager.getInstance().contains(m_npc_frame)) {
				if (m_npc_frame != null) {
					DWControlsManager.getInstance().removeControl(m_npc_frame);
				}
			}
			m_npc_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
			DWControlsManager.getInstance().addControl(m_npc_frame);

			DWTitle m_tit = new DWTitle("", m_npc_frame);
			m_npc_frame.addControl(m_tit);
			DWImageBox m_tit_ima = new DWImageBox(m_cr_jiesuan_tit);
			m_tit_ima.setNearAnchor(m_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			m_npc_frame.addControl(m_tit_ima);
			DWImageBox m_tuichu = new DWImageBox(m_cr_tuichu);
			m_tuichu.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					DWControlsManager.getInstance().removeControl(m_npc_frame);
				}
			});
			m_tuichu.setNearAnchor(m_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
			m_tuichu.setTouchZoomIn(20, 20);
			m_npc_frame.addControl(m_tuichu);

			DWBackground m_sxbj = new DWBackground(m_npc_frame.getShowWidth() - 30, 3 * (m_npc_frame.getShowHeight() - (m_tit.getShowHeight() - 20) - 10 - 10 - 15) / 4);
			m_sxbj.setNearAnchor(m_npc_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 15, (m_tit.getShowHeight() - 20) + 15);
			m_npc_frame.addControl(m_sxbj);

			DWBackground m_xxbj = new DWBackground(m_npc_frame.getShowWidth() - 30, (m_npc_frame.getShowHeight() - (m_tit.getShowHeight() - 20) - 10 - 10 - 15) / 4);
			m_xxbj.setNearAnchor(m_sxbj, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
			m_npc_frame.addControl(m_xxbj);

			DWButton m_but = new DWButton("进入杀场", m_cr_but);
			m_but.setDownImage(m_cr_but_anxiz);
			m_but.setNearAnchor(m_sxbj, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
			m_npc_frame.addControl(m_but);
			m_but.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					DWGameManager.getInstance().getSendMessage().sendShuraBattleJoin(m_battle_id);
				}
			});

			DWTextbox m_tb = new DWTextbox("天罡星与地煞星无尽战斗的战场，唯有杀戮是你剩下的唯一本能", m_sxbj.getShowWidth() - 20, m_sxbj.getShowHeight() - m_cr_but.getHeight() - 10 - 20);
			m_tb.setNearAnchor(m_sxbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
			m_npc_frame.addControl(m_tb);

			DWTextbox m_tb_down = new DWTextbox("定时开放的杀场，根据杀人和助攻数奖励战功和道具", m_xxbj.getShowWidth() - 20, m_xxbj.getShowHeight() - 20);
			m_tb_down.setNearAnchor(m_xxbj, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			m_npc_frame.addControl(m_tb_down);
		}
	}

	/**
	 * 进入战场成功与否的接收指令
	 * 
	 * @param dis
	 * @throws IOException
	 */
	// public boolean m_flag = true;
	public void recvBattleJoin(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_修罗杀场);
		byte m_state = dis.readByte();
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "进入战场失败。");
		} else if (m_state == 1) {
			if (DWControlsManager.getInstance().contains(m_npc_frame)) {
				if (m_npc_frame != null) {
					DWControlsManager.getInstance().removeControl(m_npc_frame);
				}
			}
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功进入战场。");
			// m_flag = false;
		}
	}

	/**
	 * 每5秒钟发一次请求的即时分数的接收指令
	 */
	public Battle m_jishi_score = null;
	public short m_size = 0;
	public int m_five_second_sendmessage = 0;
	public long m_sendmessage_current = 0;

	public void recvBattleJiShiScore(DataInputStream dis) throws IOException {
		m_jishi_score = new Battle();
		m_jishi_score.recvRightRole(dis);
		// if(!m_flag)
		// {
		// m_flag = true;
		m_five_second_sendmessage = 5;
		m_sendmessage_current = System.currentTimeMillis();
		// }
		UIWindows.getInstance().m_main.closeTaskList();
		RightRoleScore();
	}

	public DWListbox m_right_listbox = null;
	public DWBackground m_right_listbox_bg = null;
	DWTextbox m_tb[] = null;

	public void RightRoleScore() {
		if (m_size == m_jishi_score.m_right_role_size) {
			if (UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox_bg) && UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox)) {
				if (m_right_listbox_bg != null && m_right_listbox != null) {
					for (int i = 0; i < m_jishi_score.m_right_role_size; i++) {
						if(i!=m_jishi_score.m_right_role_size-1)
						{
							m_tb[i].setText( "<mark c="+getNameColor(ItemConstants.稀有度_白)+">"+m_jishi_score.m_right_role_name[i] + "："  + m_jishi_score.m_right_role_score[i] + "分"+"</mark>");
						}
						else
						{
							m_tb[i].setText("<mark c=FFBB11>" + m_jishi_score.m_right_role_name[i] + "："  + m_jishi_score.m_right_role_score[i] + "分"+"</mark>");
						}
					}
				}
			} else if (!UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox_bg)) {
				m_size = m_jishi_score.m_right_role_size;
				Right_right();
			}
		} else {
			m_size = m_jishi_score.m_right_role_size;
			if (UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox_bg)) {
				UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_right_listbox_bg);
				m_right_listbox.removeAllSubItem();
				UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_right_listbox);
				m_right_listbox_bg = null;
				m_right_listbox = null;
			}
			Right_right();
		}
	}

	public void Right_right() {
		m_right_listbox_bg = new DWBackground(DWFont.getDefaultFont().getFontSize() * 10 + 10, (m_jishi_score.m_right_role_size) * ((int) (DWFont.getDefaultFont().getFontHeight()) + 5) + 10);
		m_right_listbox_bg.setNearAnchor(UIWindows.getInstance().m_main.m_Uimain_Frame, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, -10);

		m_right_listbox = new DWListbox(DWFont.getDefaultFont().getFontSize() * 10, (m_jishi_score.m_right_role_size) * ((int) (DWFont.getDefaultFont().getFontHeight()) + 5));
		m_right_listbox.setShowBackgroundRect(false);
		m_right_listbox.setNearAnchor(m_right_listbox_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

		UIWindows.getInstance().m_main.m_Uimain_Frame.addControl(m_right_listbox_bg);
		UIWindows.getInstance().m_main.m_Uimain_Frame.addControl(m_right_listbox);

		m_tb = new DWTextbox[m_jishi_score.m_right_role_size + 2];
		for (int i = 0; i < m_jishi_score.m_right_role_size; i++) {
			DWListSubItem m_lsi = new DWListSubItem();
			if(i!=m_jishi_score.m_right_role_size-1)
			{
				m_tb[i] = new DWTextbox( "<mark c="+getNameColor(ItemConstants.稀有度_白)+">"+m_jishi_score.m_right_role_name[i] + "："  + m_jishi_score.m_right_role_score[i] + "分"+"</mark>",
						m_right_listbox.getShowWidth());
			}
			else
			{
				m_tb[i] = new DWTextbox("<mark c=FFBB11>" + m_jishi_score.m_right_role_name[i] + "："  + m_jishi_score.m_right_role_score[i] + "分"+"</mark>",
						m_right_listbox.getShowWidth());
			}
			m_tb[i].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
			m_lsi.addControls(m_tb[i]);
			m_right_listbox.addSubItem(m_lsi);
		}
	}

	/**
	 * 中途主动退出战场的接收指令
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvExitBattlefield(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_修罗杀场);
		byte m_state = dis.readByte();
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "退出战场失败。");
		} else if (m_state == 1) {
			m_size = 0;
			long m_zhangong = dis.readLong();
			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "杀场还未结束，确定退出？" + DWControlTools.CHANGE_ROW + "当前分数奖励" + m_zhangong + "战功。", "确定", "取消");
			DWControlsManager.getInstance().addControl(m_mb);
			m_mb.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
						DWGameManager.getInstance().getSendMessage().sendZhongTuiLeave();
					} else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
					}
					DWControlsManager.getInstance().removeControl(m_mb);
				}
			});
		}
	}

	/**
	 * 修罗战场的最后结算界面的接收指令
	 */
	public Battle m_battle_list = null;// /结算界面的battle的对象

	public void recvSettleAccounts(DataInputStream dis) throws IOException {
		if (m_battle_list != null) {
			m_battle_list = null;
		}
		m_battle_list = new Battle();
		m_battle_list.recvMoreRole(dis);
		m_battle_list.recvSigleRole(dis);
		m_battle_list.recvItem(dis);
		m_djs_time = 10;
		m_current = System.currentTimeMillis();
		BattleJieSuan();
	}

	/**
	 * 最终离开战场时的接收指令
	 */
	public void recvLeave(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_修罗杀场);
		byte m_state = dis.readByte();
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "离开战场失败。");
		} else if (m_state == 1) {
			m_size = 0;
			m_djs_time = 0;
			m_current = 0;
			m_five_second_sendmessage = 0;
			m_sendmessage_current = 0;
			m_donghua_glag = true;
			UIWindows.getInstance().m_main.OpenTaskList();
			if(UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox_bg) && UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_right_listbox))
			{
				if(m_right_listbox_bg != null && m_right_listbox != null)
				{
					UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_right_listbox_bg);
					UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_right_listbox);
				}
			}
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功离开修罗杀场。");
		}
	}

	/**
	 * 倒计时5秒，重新分队的接收指令
	 */
	public boolean m_donghua_glag = true;
	public DWBackground m_donghua_bg = null;
	public int m_timer = 0;
	public int m_more_time = 0;
	public Bitmap m_cr_bitmap[] = new Bitmap[5];

	public void recvDJS(DataInputStream dis) throws IOException {
		byte m_time = dis.readByte();
		m_donghua_glag = false;
		m_more_time=4;
		if (UIWindows.getInstance().m_main.m_Uimain_Frame.contains(m_donghua_bg)) {
			UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_donghua_bg);
		}
		m_donghua_bg = new DWBackground(m_cr_bitmap[m_more_time], m_cr_bitmap[m_more_time].getWidth(), m_cr_bitmap[m_more_time].getHeight());
		m_donghua_bg.setCentre();
		UIWindows.getInstance().m_main.m_Uimain_Frame.addControl(m_donghua_bg);
		m_donghua_bg.setShow(false);
		DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "倒计时结束后重新分队。");
	}

	public int m_djs_time = 0;
	public long m_current = 0;

	public void logic() {
		/**
		 * 倒计时5秒动画效果
		 */
		if (!m_donghua_glag) {
			int way = (m_timer % (12 * 1)) / 1;
			m_donghua_bg.setBackground(m_cr_bitmap[m_more_time]);
			m_donghua_bg.setShow(true);
			m_donghua_bg.setShowWideHigh(m_cr_bitmap[m_more_time].getWidth() * way/22+m_cr_bitmap[m_more_time].getWidth()  , m_cr_bitmap[m_more_time].getHeight() * way/22 + m_cr_bitmap[m_more_time].getHeight());
			m_donghua_bg.setCentre();
			if (++m_timer > 11) {
				m_timer = 0;
				m_more_time--;
				if (m_more_time <0) {
					m_more_time = 0;
					UIWindows.getInstance().m_main.m_Uimain_Frame.removeControl(m_donghua_bg);
					m_donghua_glag = true;
				}
			}
		}

		/**
		 * 结算界面的倒计时
		 */
		if (m_djs_time > 0) {
			if (m_current == 0) {
				m_current = System.currentTimeMillis();
			}
			long m_now = System.currentTimeMillis();
			int index = (int) (m_djs_time - (m_now - m_current) / 1000);
			if (index < 0) {
				m_current = System.currentTimeMillis();
			} else {
				m_djs_tb.setText("<mark c=FFBB11" + ">" + index + "</mark>" +"<mark c="+getNameColor(ItemConstants.稀有度_红)+ "秒"+"</mark>");
				m_djs_tb.setNearAnchor(m_djs_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
				if (index == 0) {
					m_djs_time = 0;
					m_current = 0;
					DWGameManager.getInstance().getSendMessage().sendShuraBattleLeave();
				}
			}
		}

		/**
		 * 5秒钟发一次指令
		 */
		if (m_five_second_sendmessage > 0) {
			if (m_sendmessage_current == 0) {
				m_sendmessage_current = System.currentTimeMillis();
			}
			long m_current = System.currentTimeMillis();
			int m_index = (int) (m_five_second_sendmessage - (m_current - m_sendmessage_current) / 1000);
			if (m_index < 0) {
				m_index = 0;
			} else {
				Tools.debugPrintln("m_index:" + m_index);
				if (m_index == 0) {
					m_five_second_sendmessage = 0;
					m_sendmessage_current = 0;
					DWGameManager.getInstance().getSendMessage().sendJiShiScore();
				}
			}
		}
	}
}
